using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Colman.Rpg.Npc;
using Colman.Rpg.Pvp;
using Colman.Rpg.Messaging;
using Colman.Rpg.Connection;

namespace Colman.Rpg
{
    /// <summary>
    /// The main menu.
    /// </summary>
    public partial class MenuForm : ConnectionAwareForm
    {
        /// <summary>
        /// Creates a new instance of <see cref="MenuForm" />.
        /// </summary>
        public MenuForm()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnNpc_Click(object sender, EventArgs e)
        {
            new WorldForm().ShowDialog(this);
        }

        private void btnPvp_Click(object sender, EventArgs e)
        {
            new ChatForm().ShowDialog(this);
            ClientEndPoint.Instance.SendMessage(new ChatRoomLeaveRequest());
        }

        /// <summary>
        /// Called when a message is received from the server.
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">The message arguments.</param>
        protected override void OnMessageReceived(object sender, Colman.Rpg.Connection.MessageReceivedEventArgs e)
        {
            base.OnMessageReceived(sender, e);

            PlayerInformationResponse response = e.Message as PlayerInformationResponse;

            if (response != null)
            {
                CharacterSheetForm form = new CharacterSheetForm();
                form.SetPlayer(response.Player, 0);

                form.ShowDialog(this);
            }
        }

        private void btnCharacterSheet_Click(object sender, EventArgs e)
        {
            ClientEndPoint.Instance.SendMessage(new PlayerInformationRequest());
        }

        private void btnShop_Click(object sender, EventArgs e)
        {
            new MarketForm().ShowDialog(this);
        }
    }
}